//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "FunctionElemIndictor.h"
#include "Function.h"

registerMooseObject("O4App", FunctionElemIndictor);

template <>
InputParameters
validParams<FunctionElemIndictor>()
{
  InputParameters params = validParams<ElementIntegralIndicator>();
  params.addRequiredParam<FunctionName>("function", "The analytic solution to compare against");
  params.addClassDescription("Compute the square of the error as the difference between an unknown "
                             "variable and an analytical solution.");
  return params;
}

void
FunctionElemIndictor::computeIndicator()
{
  Real sum = 0;
  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
    sum += _JxW[_qp] * _coord[_qp] * computeQpIntegral();

   sum /= _current_elem_volume;

  _field_var.setNodalValue(sum);
}


FunctionElemIndictor::FunctionElemIndictor(const InputParameters & parameters)
  : ElementIntegralIndicator(parameters), _func(getFunction("function"))
{
}

Real
FunctionElemIndictor::computeQpIntegral()
{
  return _func.value(_t, _q_point[_qp]);
}
